﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PMS.Helper;
using PMS.BLL;
using PMS.DBUtility;
namespace PMS
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(cmb_type.SelectedValue.ToString());
            BLL.Dd blldd = new Dd();
            Model.DDinfo ddinfo = new PMS.Model.DDinfo();
            ddinfo.Id = "";
            ddinfo.Name = txt_name.Text;
            ddinfo.Model = txt_model.Text;
            ddinfo.NamePY = txt_py.Text;
            ddinfo.Price = double.Parse(txt_price.Text);
            ddinfo.Shelf = txt_shelf.Text;
            ddinfo.CategoryId = cmb_type.SelectedValue.ToString();
            ddinfo.Numbers = helper.GetNumber("");
            if (blldd.Insert(ddinfo))
            {
                MessageBox.Show("添加成功!");
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
            
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            
            BLL.Category categorybll = new PMS.BLL.Category();
            BLL.Unit unitbll = new BLL.Unit();
            cmb_type.DataSource = categorybll.GetAllList();
            cmb_type.DisplayMember = "Name";
            cmb_type.ValueMember = "Id";
            cmb_unit.DataSource = unitbll.GetAllList();
            cmb_unit.DisplayMember = "UnitName";
            cmb_unit.ValueMember = "Id";
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txt_name_TextChanged(object sender, EventArgs e)
        {
            txt_py.Text = helper.GetPYCode(txt_name.Text);
        }
    }
}
